$(function () {
    //上滑事件触发瀑布流
    $('.weui-navbar__item').on('click', function () {
        $(this).addClass('weui-bar__item_on').siblings('.weui-bar__item_on').removeClass('weui-bar__item_on');
    });

    $('.wanna-buy').on('click', function () {
        location.href = 'index.html';
    });
    // 页数
    page = 0;
    // 每页展示5个
    pageSize = 5;

    //预加载
    findAllWannasItem(pageSize, page);
    // dropload
    $('.m-container').dropload({
        scrollArea: window,
        loadDownFn: function (me) {
            page++;

            findAllWannasItem(pageSize, page, me)
            me.resetload();
        }
    });

    function findAllWannasItem(pageSize, page, me) {
        page++;
        var result = Model.wannas.findAllWannasItem({
            pageSize: pageSize,
            page: page
        });

        if (result.users.length == 0) {
            // 锁定
            me.lock();
            // 无数据
            me.noData();
        } else {
            for (var i = 0; i < result.users.length; i++) {


                var item = ' <div class="per-all-info">' +
                    '            <a href="#">' +
                    '                <div class="per-wanna-info">' +
                    '                    <div class="wanna-user-title weui-cell">' +
                    '                        <img class="wanna-user-head-image" src="' + result.users[i].photo + '">' +
                    '                        <div class="float-left">' +
                    '                            <h2>' + result.users[i].nickname + '</h2>' +
                    '                            <p class="color-eee">' + result.wannas[i].createtime + '来自[' + result.users[i].school + ']</p>' +
                    '                            <span>期望价格：￥' + result.wannas[i].price + '</span>' +

                    '                        </div>' +
                    '                    </div>' +
                    '                    <div class="wanna-content">' +
                    '                        <p>' + result.wannas[i].content + '</p>' +
                    '                        <span class="wannaindex' + i + '"></span>' +

                    '                    </div>' +
                    '' +
                    '                </div>' +
                    '            </a>' +
                    '            <div class="wanna-item">' +
                    '                <a class="item" href="views/chat.html?userid=' + result.users[i].userid + '"><img src="img/icon/wanna_item_1.png"><span' +
                    '                        class="wanna-item-font">私信</span></a>' +
                    '                <a class="item comment"><img src="img/icon/wanna_item_2.png"><span class="wanna-item-font">评论</span></a>' +
                    '                <a class="item dianzan-icon"><img src="img/icon/wanna_item_3.png" class="dianzan"><span class="wanna-item-font">点赞</span></a>' +
                    '            </div>' +
                    '        </div>';
                $('.list-wanna-buy').append(item);
                for (var j = 0; j < result.wannas[i].wannaImg.length; j++) {
                    var item = '<img  src="' + result.wannas[i].wannaImg[j].image + '" class="wanna-img">';
                    $('.wannaindex' + i + '').append(item);
                }
            }
        }
    }
})

// 点击图片放大
$(document).on('click', '.wanna-img', function () {
    var url = $(this).attr('src');
    var gallery = weui.gallery(url, {
        className: 'custom-classname',
        onDelete: function () {
            gallery.hide(function () {
                console.log('`gallery` has been hidden');
            });
        }
    });
});


//收藏

$(document).on('click', '.dianzan', function () {
    // var goodsid = $(this).attr("good-id");
    // var result2 = Model.goods.collectGoods({
    //     goodsid: goodsid
    // })
    //
    // if (result2.code == 1) {
    $(this).attr('src', 'img/icon/wanna-dianzan.png');
    // }

})


$(document).on('click', '.comment', function () {
    weui.toast('暂未开发，敬请期待！', {
        duration: 1500,
        className: 'custom-classname',
    });

})